﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using AspNetCs.Model;
using AspNetCs.Bll;
using AspNetCs.Common;

public partial class AncestralHallBBS_PublishBBS :BasePage
{

    protected string userName = "";
    protected AncestralHallBBSMsg_BLL bll = AncestralHallBBSMsgBLL.CreateNew;

    protected AncestralHallBBS_Model ancestralHallBBSModel = new AncestralHallBBS_Model();

    protected AncestralHallBBSBLL ancestralHallBBSBLL = AncestralHallBBS_BLL.CreateNew;
    protected int AncestralHallItemId = 0;
    protected int AncestralHallId = 0;

    protected void Page_Load(object sender, EventArgs e)
    {
        userName = Base_GetUserInfo.UserName;
        txtName.Text = userName;
        if(!IsPostBack)
        {
            AncestralHallItemId = StringHelper.isNumber_int(Request["AncestralHallItemId"]);
            ViewState["AncestralHallItemId"] = AncestralHallItemId;
            AncestralHallId = StringHelper.isNumber_int(Request["AncestralHallId"]);
            ViewState["AncestralHallId"] = AncestralHallId;
        }
        else
        {
            if (ViewState["AncestralHallItemId"] != null)
            {
                AncestralHallItemId = StringHelper.isNumber_int(ViewState["AncestralHallItemId"].ToString());
            }
            if (ViewState["AncestralHallId"]!=null)
            {
                AncestralHallId = StringHelper.isNumber_int(ViewState["AncestralHallId"].ToString());
            }
        }
        GetAncestralHallModel();
        
    }

    public void GetAncestralHallModel()
    {
        ancestralHallBBSModel = ancestralHallBBSBLL.GetModel("AncestralHallId=" + this.AncestralHallId + "and IsDel=0");

    }

    public void pageInit()
    { 
        
    }

    public void PublisMsg()
    {
        AncestralHallBBSMsgModel msgModel = new AncestralHallBBSMsgModel();
        msgModel.AncestralHallItemId = this.AncestralHallItemId;
        msgModel.Content = WebEditor1.Text;
        msgModel.Hits = 0;
        msgModel.PublishTime = DateTime.Now;
        msgModel.Title = txtTitle.Text;
        msgModel.UserId = Base_GetUserInfo.UserId;
        bll.Add(msgModel);
        
    }


    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        PublisMsg();
        ResultStr("BBSIndex.aspx?AncestralHallId=" + this.AncestralHallId + "&AncestralHallItemId=" + this.AncestralHallItemId + "&accessType=1", "发帖成功!");
    }
}
